﻿// ***********************************************************************
// Project			: Micua
// Assembly         : Micua.BLL
// Author           : iceStone
// Created          : 2013-11-23 21:59
//
// Last Modified By : iceStone
// Last Modified On : 2013-11-23 22:06
// ***********************************************************************
// <copyright file="LinkService.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary>Link管理类 LinkManager</summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Micua.Core.Caching;
using Micua.Model;
using Micua.Model.Struct;

namespace Micua.BLL
{
    /// <summary>
    /// Link管理类 LinkManager
    /// </summary>
    /// <remarks>
    ///  2013-11-23 22:08 Created By iceStone
    /// </remarks>
    public partial class LinkService
    {
        /// <summary>
        /// 根据传入委托筛选出对应的数据实体集合
        /// </summary>
        /// <remarks>
        ///  2013-11-23 22:08 Created By iceStone
        /// </remarks>
        /// <param name="predicate">筛选条件表达式</param>
        /// <returns>查询到数据实体集合</returns>
        public override IQueryable<Link> Query(Expression<Func<Link, bool>> predicate)
        {
            var res = CacheHelper.Get<IQueryable<Link>>(CacheKeys.LinkList);
            if (res != null) return res.Where(predicate).AsQueryable();

            res = base.Query();
            CacheHelper.Set(CacheKeys.LinkList, res, TimeSpan.FromDays(10));
            return res.Where(predicate);
        }

        /// <summary>
        /// 根据传入委托筛选出对应的数据实体集合
        /// </summary>
        /// <remarks>
        ///  2013-11-23 22:08 Created By iceStone
        /// </remarks>
        /// <param name="predicate">筛选条件表达式</param>
        /// <returns>查询到数据实体集合</returns>
        public IList<Link> SelectFormatList(Func<Link, bool> predicate)
        {
            var res = CacheHelper.Get<IList<Link>>(CacheKeys.LinkFormatList);
            if (res != null) return res.Where(predicate).ToList();
            res = base.Query().ToList();
            CacheHelper.Set(CacheKeys.LinkFormatList, res, TimeSpan.FromDays(10));
            return res.Where(predicate).ToList();
        }
    }
}
